// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import './assets/style/reset.css'
import './assets/style/main.css'
// import 'element-ui/lib/theme-chalk/index.css'
// import ElementUI from 'element-ui'
import pub from './assets/script/pub.js'
import axios from './assets/script/axios.js'
Vue.prototype.$pub = pub
Vue.prototype.$axios = axios

// Vue.use(ElementUI)

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next({ path: '/login' })
  } else {
    if (to.path !== '/login') {
      axios.request('post', '/Account/GetUserState')
        .then((res) => {
          if (res.code === 0) {
            if (res.data.state === 1) {
              next()
            } else {
              axios.alert('用户未登录或登录超时', '提示', function () {
                next({ path: '/login' })
              })
            }
          }
        })
    } else {
      next()
    }
  }
})

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
